'''
Created on 2011-1-26

@author: Q
'''
import os, thread, socket, string
port = 11125
hostname = "fs3.das4.tudelft.nl"



def RunTimeManager():
#    thread.start_new_thread(listenNewJobs, ())
    return True

def submitExps(expName, factors, numOfExperiments, servername="anyServer", ipAddress=hostname):
    for i in range(0, numOfExperiments):
        instances = 1;
        s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
        s.connect((ipAddress,port))
        s.settimeout(5)
        paras = " " + servername + " %d"%instances
        for factor in factors:
            paras = paras + " %d"%factor
        s.send(expName + paras)
        content = s.recv(1024)
        if string.strip(content) == "ok":
            print "submit " + expName, factors, instances, servername
        s.close()
        
if __name__ == "__main__":
    #submit job to DAS-4
#    submitExps("quick-1a1", [1], 1, "anyServer", "127.0.0.1")
    #submit job to Cloud
#    submitExps("1a1", [1], 10, "m1.small", "127.0.0.1")
    #submit a experiment called "1a1" to run in local and repeated 2 times.
#    submitExps("1a1", [1], 2, "local", "127.0.0.1") 
    #submit to run 1a1 with factor 1 to 4. See configuration.py for the meaning of the factors
    #factor 1 means start Rondje, factor 2 means start Rondje and Convoy, factor 3 means start Rondje, Convy and PathZilla
    submitExps("1a1", [8,9,10,11,12,13,14,15,16], 1, "local", "127.0.0.1")
    